package sample.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import sample.user.dao.UserMapperAnnotation;
import sample.user.entity.UserEntity;
import sample.user.service.UserServiceAnnotation;


@Service
public class UserServiceAnnotationImpl implements UserServiceAnnotation {

	@Autowired
	private UserMapperAnnotation userMapperAnnotation;
	
	public String getUser(){
		
		List<UserEntity> userEntities = userMapperAnnotation.getUser();
		
		ObjectMapper objectMapper = new ObjectMapper();
		String result = "";
		try {
			result = objectMapper.writeValueAsString(userEntities);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		
		
		return result;
	}

	@Override
	public void addUser(UserEntity userEntity) {
		userMapperAnnotation.addUser(userEntity);
		
	}

	@Override
	public void deleteUser(int id) {
		userMapperAnnotation.deleteUser(id);
		
	}

	@Override
	public void updateUser(UserEntity userEntity) {
		userMapperAnnotation.updateUser(userEntity);
		
	}
}
